package com.lagou.dao.impl;

import java.util.ArrayList;
import java.util.List;

import javax.sql.rowset.CachedRowSet;

import com.lagou.dao.SecondDao;
import com.lagou.entity.Second;
import com.lagou.util.JDBCUtil2;

public class SecondDaoImpl implements SecondDao {
	JDBCUtil2 util=JDBCUtil2.getInit();
	@Override
	public Second queryBySid(int sid) {
		CachedRowSet rs=util.query("\r\n" + 
				"select t_second.fid,ftype,sid,sname from t_second ,t_first where t_second.fid=t_first.fid and t_second.sid=?", sid);
		try {
			while(rs.next()) {
				Second s=new Second();
				s.setSid(rs.getInt("sid"));
				s.setsName(rs.getString("sname"));
				s.setFid(rs.getInt("fid"));
				return s;
			}
			
		} catch (Exception e) {
			e.printStackTrace();
		}finally {
			util.closeCacheRowSet(rs);
		}
		return null;
	}
	@Override
	public List<Integer> querySid() {
		List<Integer> list = new ArrayList<Integer>();
		String sql="select sid from t_second";
		CachedRowSet rs=util.query(sql);
		try {
			while(rs.next()) {
				int b=new Integer(rs.getInt("sid"));
//				int a=new Integer(rs.getInt("fid"));
//				list.add(a);
				list.add(b);
			}
			
		} catch(Exception e) {
			e.printStackTrace();
		}finally {
			util.closeCacheRowSet(rs);
		}
		return list;
	}
}
